/*
 *  Document   : index
 *  Created on : 30/01/2012, 09:45:33 PM
 *  Author     : Jhon F Triana
 */
package persistencia;
import java.sql.*;

public class Conexion
{
    private final String Controler = "org.postgresql.Driver";
    private final String URL = "jdbc:postgresql://localhost/EIS?user=postgres&password=eis";

    private Connection Connection;
    private Statement Statement;
    private static Conexion con = null;

    private Conexion()
    {
        try
        {
            Class.forName(this.Controler);
        }
        catch(ClassNotFoundException ex){System.out.println("Driver No encontrado: "+ex.toString());}
        try 
        {
            this.Connection = DriverManager.getConnection(URL);
            this.Statement = this.Connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        }
        catch(Exception ex){System.out.println("Error en conexion: "+ex.toString());}
    }

    static public Conexion getConexion()
    {
        if(con==null)
        {
            con = new Conexion();
            return con;
        } 
        return con;
    }     
    
    public ResultSet getQuery(String Query){
        ResultSet result = null;
        try{
            result = this.Statement.executeQuery(Query);
        }
        catch(Exception ex){System.out.println("Error en la consulta: " + Query+" "+ex.toString());}
        return(result);
    }
    
}


